package org.yray.lock;

import java.util.concurrent.locks.ReentrantLock;

public class LockTest {
    public static void main(String[] args) throws InterruptedException {
        ReentrantLock lock=new ReentrantLock();
        Thread t=new Thread(()->{
            lock.lock();
            System.out.println(System.currentTimeMillis()+":"+Thread.currentThread().getName()+"1:get lock");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        });
        t.start();
        Thread t2=new Thread(()->{
            lock.lock();
            System.out.println(System.currentTimeMillis()+":"+Thread.currentThread().getName()+"2:get lock");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        });
        t2.start();
        Thread.sleep(5000);
        Thread t3=new Thread(()->{
            lock.lock();
            System.out.println(System.currentTimeMillis()+":"+Thread.currentThread().getName()+"3:get lock");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        });
        t3.start();


        Thread.sleep(5*60*1000);

    }
}
